<template>
  <el-dialog title="拉取信息" :visible.sync="getInfoShow" width="70%">
      <el-table :data="gameData" v-loading="loading" stripe>
        <el-table-column label="排序" align="center" min-width="80" fixed>
          <template slot-scope="scope">
            {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="游戏品类" align="center" prop="index" min-width="120rpx">
          <template slot-scope="scope">
            <span>{{ getGameName(scope.row.dictCodeId) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="游戏账号" align="center" prop="account" min-width="120rpx"/>
        <el-table-column label="账号描述" align="center" prop="accountDescription" min-width="120rpx">
          <template v-slot="scope">
            <el-popover trigger="hover" placement="top">
              <p class="hover-multi-line">{{ $line(scope.row.accountDescription) }}</p>
              <div slot="reference" class="hover-slot-line">
                {{ scope.row.accountDescription }}
              </div>
              <div style="text-align: center;">
                <el-button type="primary" plain size="mini" @click="handleCopy(scope.row.accountDescription)">复制
                </el-button>
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="销售渠道" align="center" prop="saleChannel" min-width="120rpx"/>
        <el-table-column label="销售金额" align="center" prop="saleAmount" min-width="120rpx"/>
        <el-table-column label="出售时间" align="center" prop="createTime" min-width="140rpx"/>
        <el-table-column label="入库时间" align="center" prop="storageTime" min-width="140rpx"/>
        <el-table-column label="操作" align="center" prop="index" min-width="120rpx" fixed="right">
          <template slot-scope="scope">
            <el-button slot="reference" size="mini" type="text" @click="handleConfirmOrder(scope.row)">
              <span style="color: rgba(83, 90, 244, 1);">确认订单</span>
            </el-button>
          </template>
        </el-table-column>
      </el-table>

    <div slot="footer" class="dialog-footer">
      <el-button @click="getInfoShow = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import {
  adoptApi,
  getAccomplishedApi
} from '@/api/business/abnormal'

export default {
  props: {
    gameList: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      getInfoShow: false,
      account: '',
      Processld: '',
      gameData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },

    }
  },

  methods: {
    // 确认订单
    handleConfirmOrder(item) {
      this.$confirm('您确定要确认该订单吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        getAccomplishedApi({
          processId: this.Processld,
          tStockId: item.id
        }).then(res => {
          this.$message.success("确认成功！");
          this.getData();
        }).catch(err => {
          this.$message.error(err);
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 打开弹框
    handleOpen(account, Processld) {
      this.getInfoShow = true;
      this.Processld = Processld;
      this.account = account;
      this.getData();
    },

    handleClose() {
      this.getInfoShow = false;
    },

    // 获取确定订单数据
    getData() {
      this.loading = true;
      adoptApi(this.account).then(res => {
        this.loading = false;
        this.gameData = res.data;
      })
    },

    // 复制
    handleCopy(e) {
      const el = document.createElement('textarea');
      el.value = e;
      document.body.appendChild(el);
      el.select();
      document.execCommand('copy');
      document.body.removeChild(el);
      // 通知用户已复制
      this.$message({
        message: '复制成功！',
        type: 'success'
      });
    },

    // 获取游戏名称
    getGameName(gameid) {
      var game = this.gameList.find(i => i.dictCode == gameid);
      if (game != undefined) {
        return game.dictLabel;
      } else {
        return "-";
      }
    }
  }
}
</script>
